package fr.neyb.bernouilli.problem018;

import java.util.HashSet;
import java.util.Set;

public class Node {

	private final int value;

	private final Set<Node> parents;
	private final Set<Node> children;

	public UnmodifiableNode getUnmodifiableNode() {
		return new UnmodifiableNode(this);
	}

	public Node(int value, Set<Node> parents, Set<Node> children) {
		this.value = value;
		this.parents = parents;
		this.children = children;
	}

	public Node(int value) {
		this.value = value;
		this.parents = new HashSet<>();
		this.children = new HashSet<>();
	}

	public Node(Node copy) {
		value = copy.value;
		parents = copy.parents;
		children = copy.children;
	}

	public int getValue() {
		return value;
	}

	public Set<Node> getParents() {
		return parents;
	}

	public Set<Node> getChildren() {
		return children;
	}

	public void addParent(Node parent) {
		parent.children.add(this);
		parents.add(parent);
	}

	@Override
	public String toString() {
		return String.valueOf(value);
	}
}
